import request from '@/utils/_request'

// 查询菜单列表
export function listMenu(query) {
    return request({
        url: '/admin/menu/query',
        method: 'post',
        data: query
    })
}

// 查询菜单详细
export function getMenu(menuId) {
    return request({
        url: '/admin/menu/queryById/' + menuId,
        method: 'get'
    })
}

// 查询菜单下拉树结构
export function treeselect() {
    const data = {
        "name": null,
        "pageNo": null,
        "pageSize": null,
        "status": null
    }
    return request({
        url: '/admin/menu/query',
        data: data,
        method: 'post'
    })
}

// 根据角色ID查询菜单下拉树结构
export function roleMenuTreeselect(roleId) {
    return request({
        url: '/admin/role/menu/queryById/' + roleId,
        method: 'get'
    })
}

// 新增菜单
export function addMenu(data) {
    const ref = {
        menuDirectoryDto: null,
        menuDto: null,
        menuButtonDto: null
    }
    if (data.type === 1) {
        ref.menuDirectoryDto = data
    }
    if (data.type === 2) {
        ref.menuDto = data
    }
    if (data.type === 3) {
        ref.menuButtonDto = data
    }
    return request({
        url: '/admin/menu/add',
        method: 'post',
        data: ref
    })
}

// 修改菜单
export function updateMenu(data) {
    const ref = {
        menuDirectoryDtoEdit: null,
        menuDtoEdit: null,
        menuButtonDtoEdit: null
    }
    if (data.type === 1) {
        ref.menuDirectoryDtoEdit = data
    }
    if (data.type === 2) {
        ref.menuDtoEdit = data
    }
    if (data.type === 3) {
        ref.menuButtonDtoEdit = data
    }
    return request({
        url: '/admin/menu/edit',
        method: 'put',
        data: ref
    })
}

// 删除菜单
export function delMenu(id) {
    const data = {
        id: null,
        ids: null
    }
    if (id.length > 1) {
        data.ids = id
    } else {
        data.id = id
    }
    return request({
        url: '/admin/menu/delete',
        method: 'delete',
        data: data
    })
}